package com.ocean.queue;

import java.util.Arrays;

public class ArrayQueue {
    private int[] items;
    private int n;
    private int tail;
    private int head;


    public ArrayQueue(int n) {
        this.items = new int[n];
        this.n = n;
    }


    public boolean enqueue(int ele) {
        if (tail == n) {
            return false;
        }
        items[tail] = ele;
        tail++;
        return true;
    }

    public int dequeue() {
        if (tail == 0) {
            return -1;
        }
        return items[head++];
    }

    public void print() {
        System.out.println(Arrays.toString(items));
    }

    public static void main(String[] args) {
        ArrayQueue queue = new ArrayQueue(5);
        queue.enqueue(2);
        queue.enqueue(5);
        queue.enqueue(7);
        queue.enqueue(8);
        queue.enqueue(6);
        queue.enqueue(3);
        queue.print();
        int dequeue = queue.dequeue();
        System.out.println(dequeue);
        queue.print();
    }
}
